﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace wxtools
{
    public class SimpleLogTrace
    {
        /// <summary>
        /// 简单日志记录
        /// </summary>
        /// <param name="msg"></param>
        public static void WriteLog(string msg, bool showParamter = false)
        {
            try
            {
                string path = AppDomain.CurrentDomain.BaseDirectory + "\\Log\\" + DateTime.Now.ToString("yyyyMMdd") + "\\";
                if (!Directory.Exists(path))//判断是否有该文件              
                    Directory.CreateDirectory(path);
                string logFileName = path + "\\service_" + DateTime.Now.ToString("yyyyMMddHH") + ".log";//生成日志文件  
                if (!File.Exists(logFileName))//判断日志文件是否为当天  
                    File.Create(logFileName).Close();//创建文件  

                StreamWriter writer = File.AppendText(logFileName);//文件中添加文件流  
                writer.WriteLine("");
                writer.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff") + " " + msg);
                writer.WriteLine("");
                writer.Flush();
                writer.Close();
            }
            catch (Exception e)
            {

            }
        }
    }
}
